<?php

namespace App\Http\Controllers\user;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{
    //
    public function index(){
        return view('user.login');
    }
    public function login(){
        //验证
        $this->validate(request(),[
            'email' => 'required|email',
            'password' => 'required|min:5|max:20',
            'is_remember' => 'integer',
        ]);

        $user = request(['email','password']);
        $is_remember = boolValue(request('is_remember'));
        if(\Auth::attempt($user,$is_remember)){
            return redirect('/posts');
        }
        return redirect()->back()->withErrors("邮箱或密码错误");
    }
    public function logout(){
        \Auth::logout();
        return redirect('/login');
    }
}
